home *** CD-ROM | disk | FTP | other *** search
- Path: altair.dur.ac.uk!d51qvn
- From: P D Johnson <P.D.Johnson@durham.ac.uk>
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: New printf - like function, is it possible?
- Followup-To: comp.lang.c,comp.lang.c++
- Date: 1 Feb 1996 20:30:39 GMT
- Organization: University of Durham, Durham, UK.
- Message-ID: <4er7tf$f0u@mercury.dur.ac.uk>
- References: <4eqb3a$2r5@pan.otol.fi>
- NNTP-Posting-Host: altair.dur.ac.uk
- X-Newsreader: TIN [version 1.2 PL2]
-
- Timo Sakari (tkes@rhea.otol.fi) wrote:
-
- : Hi!
-
- : Do you C-gurus have any solutions to this problem?
-
- : I am programming under MS Windows 3.1 (this is NOT an OS spesific
- : question!)and I would like to create
- : some kind of modified print function, which syntax should be something
- : like normal printf; because in Windows printf can't be used, everything
- : printed to screen has to come through message boxes etc, and before
- : displaying anything, the string to displayed has to be formed. I have
- : created my own printing function, which wants parameters string and winID
- : to know where to put that string, something like this:
-
- : sprintf(printStr, "some sfuff, variables %d, %f, etc", var1, var2);
- : PrintToWin(DEBUG_WIN_1, printStr);
-
- : However, I want to write a "better" printing function, where string to be
- : formed doesn't need to be formatted first, it can be displayed and formed
- : at the same time in the same syntax like printf, something like these:
-
- : PrintToWin(DEBUG_WIN_1, "some stuff etc, %d, %f, %s, var1, var2, str1);
- : PrintToWin(OTHER_WIN, "anything that printf accepts");
-
- : So I want to print almost anything with this function without having
- : to write many functions to different argument types/number of arguments.
- : This should be possible in C++ (is it?), but is it possible in C ?
- : Can this be achieved by using void pointers and macros etc., or should
- : I give up and don't waste my time on this?
-
- : Any help would be greatly appreciated. Thanks.
-
- You will be glad to know there is a library specialy for this :-)
-
- Have you tried looking at the supplied args function's that come with C
- that allow you to write functions that do not know how many or what type
- of parameters are being passed. printf() is an example of this if you
- look in <stdio.h> you will see it has been prototyped something like
- printf(...) were the three dots mean any parameters can be passed. The
- library <args.h>? then provides you with functions to get at the values
- of the passed parameters.
-
- You will need to follow printf()'s example of passing a string as you have
- no way of knowing what type the passed parameters are. Hence all the
- %s, %d in the string.
-
- Have fun, you will not need the function overloading abilities of C++
-
- Paul
-